#!/bin/bash

###############################################################################
# Install NCipher for release image
###############################################################################

# note that we have to do this after livemedia boot, because the install script behaves differently based on whether
# a PCI NShield is plugged in, and we don’t want our ISO build to depend on having a PCI Nshield plugged in

pushd /opt/nfast/driver
./configure
make install
popd

pushd /opt/nfast/sbin
./install
popd

/opt/nfast/bin/config-serverstartup --enable-tcp --enable-privileged-tcp
# restart the hardserver for the changes to take effect
/opt/nfast/sbin/init.d-ncipher restart

/opt/nfast/bin/nopclearfail --clear --all

mkdir -p /hd
# /dev/sda1 is the harddrive used for persistent storage
mount /dev/sda1 /hd

# Setup symlinks for /opt/nfast/kmdata/local and /data/app/subzero/wallets
mkdir -p /opt/nfast/kmdata/
rm -rf /opt/nfast/kmdata/local
ln -sf /hd/local /opt/nfast/kmdata/local
ln -sf /hd/wallets /data/app/subzero/wallets

nohup /opt/nfast/bin/see-stdioesock-serv --machine /data/app/subzero/subzero-signed.sar --userdata-sar /data/app/subzero/subzero-userdata-signed.sar > /hd/subzero-signed.stdout 2> /hd/subzero-signed.stderr &

# warm up the cache
cat /data/app/subzero/subzero-cli.jar > /dev/null
